import request from "./config";

// 获取文章列表
export const getArticleList = (params) => {
  return request({
    url: "/api/articles",
    method: "get",
    params,
  });
};

// 获取文章列表
export const getRecommendArticleList = (params) => {
  return request({
    url: "/api/articles/recommend",
    method: "get",
    params,
  });
};

// 获取文章详情
export const getArticleDetail = (id, userId) => {
  return request({
    url: `/api/articles/${id}`,
    method: "get",
    params: { userId },
  });
};

// 点赞/取消点赞
export const likeArticle = (data) => {
  return request({
    url: `/api/articles/like`,
    method: "post",
    data,
  });
};

// 写文章
export const writeArticle = (data) => {
  return request({
    url: "/api/articles",
    method: "post",
    data,
  });
};

// 更新文章
export const updateArticle = (id, data) => {
  return request({
    url: `/articles/${id}`,
    method: "put",
    data,
  });
};

// 删除文章
export const deleteArticle = (id) => {
  return request({
    url: `/articles/${id}`,
    method: "delete",
  });
};

// 检查当前用户是否已点赞
export const checkArticleLike = (data) => {
  return request({
    url: `/articles/checkLike`,
    method: "get",
    params: data,
  });
};

// 检查当前用户是否已付费
export const checkArticlePay = (data) => {
  return request({
    url: `/articles/checkPay`,
    method: "get",
    params: data,
  });
};

// 删除
export const delArticle = (id) => {
  return request({
    url: `/api/articles/${id}`,
    method: "delete",
  });
};
